package questionSolution.Question_128;

import java.util.HashMap;

public class Solution_1 {
    public int longestConsecutive(int[] nums) {
        HashMap<Integer, Integer> map = new HashMap<>();
        int res = 0;
        for (int num : nums){
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        int max = 0;
        for (int key : map.keySet()){
            if(!map.containsKey(key - 1)){
                int currentNum = key;
                int currentMax = 0;
                while(map.containsKey(currentNum)){
                    currentMax++;
                    currentNum++;
                }
                max = Math.max(max, currentMax);
            }
        }
        res = Math.max(res, max);
        return res;
    }

    static void main() {
        Solution_1 sol = new Solution_1();
        int[] nums = new int[]{1,3,4,5,6,7,9,10};
        System.out.println(sol.longestConsecutive(nums));
    }
}
